import { Service } from "cl-admin";
import BaseService from "@/service/base";
import { last } from "cl-admin/utils";
// 部门
@Service("dept")
class Dept extends BaseService {
	/**
	 * 分公司数据
	 */
	list(params) {
		return this.$get("/lists", { params });
	}
	filtrate(params) {
		console.log(params, 'filtrate')
		return this.$get("/filtrate", { params });
	}
	page(params) {
		return this.$get("/lists", { params }).then(res => {
			return {
				list: res.map(v => {
					return {
						...v,
						children: v.children.map(child => ({
							...child,
							copy: true
						}))
					};
				}),
				pagination: {
					...params,
					total: res.length
				}
			};
		});
	}
	// erp获取crm的门店信息接口
	deptList({ region, size, ...args }) {
		let params = {
			pageSize: size,
			...args
		};
		if (region && region.length) {
			params.area = last(region);
		}
		return this.$post("/deptlists", params)
			.then(res => {
				return {
					list: res.lists,
					pagination: {
						...params,
						size,
						total: res.total
					}
				};
			})
			.catch(e => {
				return {};
			});
	}
	// 删除部门信息
	remove(params) {
		return this.$post("/delete", params, { silence: true });
	}
	// 部门详情
	single(params) {
		return this.$get("/single", { params });
	}

	// 部门添加
	add(params) {
		return this.$post("/add", params, {
			silence: true
		});
	}
	// 部门修改
	update(params) {
		return this.$post("/edit", params, {
			silence: true
		});
	}
	// 分配店长
	setDeptManager(params) {
		return this.$post("/setDeptManager", params);
	}
	// 获取子部门数据
	getChildDept(params) {
		return this.$get("/childDept", { params })
	}
	// 默认客服-部门员工列表
	braDeptUser(params) {
		return this.$get("/braDeptUser", { params })
	}

	preDept(params) {
		return this.$get("/preDept", { params })
	}

	getDeptInfo(params) {
		return this.$get("/info", { params })
	}


}

export default Dept;
